﻿using System;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.Media
{
    public class VehicleCollisionSound : MonoBehaviour
    {
        public VehicleAudioComponent audioComponent;
        
        public float minInterval = 1f;
        public float minImpulse = 10;
        private float _lastPlayTime;
        private void OnCollisionEnter(Collision collision)
        {
            //UnityEngine.Debug.LogError("impulse: " +collision.impulse);

            if (collision.impulse.magnitude < minImpulse)
            {
                return;
            }
            
            if (Time.time - _lastPlayTime > minInterval) 
            {
                if (audioComponent)
                {
                    audioComponent.loopAdjustToneSound.PlayVoice(audioComponent.impactSound);
                }   
            }
        }

        public void OnEnable()
        {
            
        }
    }
}